﻿using System;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Xml;
using Microsoft.SqlServer.Types;

namespace HashFoo.SqlServer
{
    /// <summary>
    /// Sql Type utility and extension functions.
    /// </summary>
    public static class SqlTypeUtil
    {
        /// <summary>
        /// Converts a string to a <c>SqlChars</c> object.
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static SqlChars ToSqlChars(this string str)
        {
            return new SqlChars(str.ToCharArray());
        }

        /// <summary>
        /// Converts a string to a <c>SqlString</c>
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static SqlString ToSqlString(this string str)
        {
            return new SqlString(str);
        }

        /// <summary>
        /// Converts a string to <see cref="SqlXml"/>.
        /// </summary>
        /// <returns></returns>
        public static SqlXml ToSqlXml(this string str)
        {
            using (var strReader = new StringReader(str))
            using (var xmlReader = new XmlTextReader(strReader))
            {
                var sqlXml = new SqlXml(xmlReader);
                return sqlXml;
            }
        }
    }
}